home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 November / MACPOWER-1997-11.ISO.7z / MACPOWER-1997-11.ISO / Apple関連 / ResEdit 2.1.3 / Examples / PExamples / Source / XXXX.Edit.p < prev   
Text File  |  1994-09-14  |  10KB  |  331 lines

  1. {
  2. File ResXXXXEd.p
  3.  
  4. Copyright Apple Computer, Inc. 1985-1990
  5. All rights reserved.
  6. }
  7.  
  8. UNIT ResXXXXed;
  9. {XXXX Editor for ResEdit}
  10.  
  11. INTERFACE
  12.  
  13.     USES    Memtypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  14.                 ResEd;
  15.  
  16.         {$R-} {Range checking off }
  17.  
  18.     TYPE
  19.         rXXXXPtr = ^rXXXXRec;
  20.         rXXXXHandle = ^rXXXXPtr;
  21.         rXXXXRec = RECORD
  22.                                  father: ParentHandle;        { Back ptr to dad }
  23.                                  name: str255;                         { The name of this editor }
  24.                                  wind: WindowPtr;                    { This view's window }
  25.                                  rebuild: BOOLEAN;                { Set TRUE if things have changed }
  26.                                  resWasntLoaded: BOOLEAN;    { TRUE if the resource should be released when the window is closed. }
  27.                                  windowType: PossibleWindowTypes;
  28.                                  theResType: ResType;            { Type of the resource being picked or edited. }
  29.                                  theResFile: INTEGER;            { The home resfile of the window. }
  30.                                  codeResID: INTEGER;            { Resource ID of the RSSC resource containing the picker or editor. }
  31.                                  hXXXX: Handle;                        { The resource we are working on }
  32.                              END; {rXXXXRec}
  33.  
  34.     PROCEDURE EditBirth(thing: Handle; Dad: ParentHandle);
  35.  
  36.     PROCEDURE PickBirth(t: ResType; Dad: ParentHandle);
  37.  
  38.     PROCEDURE DoEvent(VAR Evt: EventRecord; myXXXX: rXXXXHandle);
  39.  
  40.     PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; myXXXX: rXXXXHandle);
  41.  
  42.     FUNCTION IsThisYours (thing: Handle; myXXXX:rXXXXHandle): BOOLEAN;
  43.  
  44.     PROCEDURE DoMenu(Menu, Item: INTEGER; myXXXX: rXXXXHandle);
  45.  
  46. IMPLEMENTATION
  47.  
  48.     CONST
  49.         windowWidth = 300;
  50.         windowHeight = 100;
  51.  
  52.         sizeOfXXXXResource = 10;
  53.         
  54.         {- - -    -  - -    -  -    - -  -    - - -  - -    - - -  -    - -  -    -}
  55.  
  56.     { Fix up the window name and title for our window. }
  57.     PROCEDURE GetNameAndTitle(VAR windowTitle, windowName: STR255; thing: Handle);
  58.  
  59.         BEGIN
  60.         windowTitle := '';
  61.         SetETitle(thing, windowTitle);
  62.         windowName := Concat('XXXX', windowTitle);
  63.         windowTitle := Concat('XXXX', windowTitle);
  64.         END;
  65.  
  66.  { **************************************************************************************** }
  67.  
  68.     PROCEDURE EditBirth(thing:Handle; dad:ParentHandle);
  69.  
  70.         VAR
  71.             myXXXX: rXXXXHandle;
  72.             myWindow: WindowPtr;
  73.             windowTitle, windowName: STR255;
  74.  
  75.         BEGIN {EditBirth}
  76.         { Prepare window title and request creation of a new window }
  77.         GetNameAndTitle(windowTitle, windowName, thing);
  78.         myWindow := EditorWindSetup(noDialog, noColor, windowWidth, windowHeight, windowTitle, windowName, TRUE, ResEdId, dad);
  79.         
  80.         { If we got a new window, then start up the editor }
  81.         IF myWindow <> NIL THEN
  82.             BEGIN
  83.             IF GetHandleSize(thing) = 0 THEN { This was called via a NEW, so make a new resource }
  84.                 FixHand(sizeOfXXXXResource, thing);
  85.  
  86.             { Get memory for and handle to our instance record }
  87.             myXXXX := rXXXXHandle(NewHandle(SIZEOF(rXXXXRec)));
  88.             IF MemError <> noErr THEN
  89.                 BEGIN
  90.                 CloseWindow(myWindow);
  91.                 WindReturn(myWindow);                { Mark the window record as being available }
  92.                 Exit (EditBirth);
  93.                 END;
  94.                 
  95.             BubbleUp(Handle(myXXXX));
  96.             HLock(Handle(myXXXX));
  97.  
  98.             WITH myXXXX^^ DO
  99.                 BEGIN
  100.                 { Put information about this incarnation of the editor and the window it is }
  101.                 { serving into our record.(always passed around in the handle myXXXX).  }
  102.                 
  103.                 father := dad;
  104.                 name := windowName;
  105.                 wind := myWindow;
  106.                 rebuild := false;
  107.                 resWasntLoaded := NOT WasItLoaded;
  108.                 windowType := editorWindow;
  109.                 theResType := 'XXXX';
  110.                 theResFile := HomeResFile (thing);
  111.                 codeResID := ResEdID;
  112.                 hXXXX := thing;
  113.                 
  114.                 { Let the main program know who is to manage this window by giving it our     }
  115.                 { instance record handle.        }
  116.                 WindowPeek(myWindow)^.refCon := ORD(myXXXX);
  117.                 END; {WITH}
  118.                 
  119.             { Set up any menus,views, etc. for this window here. }
  120.             
  121.             HUnlock(Handle(myXXXX));
  122.             END; { IF myWind <> NIL }
  123.         END; { EditBirth }
  124.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  125.  
  126.     { Not used for editors. }
  127.     PROCEDURE PickBirth(t:ResType;Dad:ParentHandle);
  128.  
  129.         BEGIN { PickBirth }
  130.         END;     { PickBirth }
  131.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  132.  
  133.     PROCEDURE DoEvent(VAR Evt:EventRecord; myXXXX:rXXXXHandle);
  134.  
  135.         VAR
  136.             MousePoint: Point;
  137.             act: BOOLEAN;
  138.  
  139.         BEGIN {DoEvent}
  140.         BubbleUp(Handle(myXXXX));             { Move our item up in memory }
  141.         HLock(Handle(myXXXX));                     { Lock it down }
  142.         WITH myXXXX^^ DO
  143.             BEGIN
  144.             { Handle event passed to us by main program.  Just like a 'real' event loop, exceptノ
  145.                  there is no loop and we don't have to handle as much because the main program
  146.                  will do all the stuff that doesn't apply to us. }
  147.                 
  148.             SetPort(wind);                                { Set the port to our window }
  149.             
  150.             CASE Evt.what OF
  151.                 mouseDown:
  152.                     BEGIN
  153.                     MousePoint := Evt.where;    { Point at which the event occured }
  154.                     GlobalToLocal(MousePoint);{ Convert event location to local coords }
  155.                                                 { Do any special mouse down processing here. }
  156.                     END; { mouseDown }
  157.                 activateEvt:
  158.                     BEGIN
  159.                     act := ODD(Evt.modifiers);
  160.                     IF act THEN
  161.                         BEGIN
  162.                         AbleMenu(editMenu, editNone);
  163.                                                 { Do any activate processing here (such as inserting a menu). }
  164.                         END
  165.                     ELSE
  166.                         BEGIN
  167.                                                 { Do any deactivate processing here (such as deleting a menu). }
  168.                         END;
  169.                     END {activateEvt} ;
  170.                 updateEvt:
  171.                     BEGIN
  172.                                                 { Do the appropriate update processing here.  Remember that 
  173.                                                     BeginUpdate has already been called. }
  174.                     PaintRect(wind^.portrect);
  175.                     END; {updateEvt}
  176.                 keyDown:
  177.                     BEGIN
  178.                                                 { Do any key processing here. }
  179.                     
  180.                     { Convert the delete character into a clear command. }
  181.                     IF (band(evt.message, charCodeMask) = deleteKey) THEN
  182.                         DoMenu (editMenu, clearItem, myXXXX)
  183.                     END; {keyDown}
  184.                 
  185.                 nullEvent:
  186.                     BEGIN
  187.                                             { Do any null event processing here (such as blinking a cursor).    }
  188.                     END;
  189.                 END;    { CASE evt.what }
  190.             END;         { WITH myXXXX^^ }
  191.             
  192.         HUnlock(Handle(myXXXX));
  193.         END;             { DoEvent }
  194.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  195.  
  196.     PROCEDURE DoInfoUpdate(oldID,newID:INTEGER;myXXXX:rXXXXHandle);
  197.  
  198.         VAR
  199.             windowTitle, windowName: STR255;
  200.  
  201.         BEGIN { DoInfoUpdate }
  202.         HLock(Handle(myXXXX));                 { Lock it down }
  203.         WITH myXXXX^^ DO
  204.             BEGIN 
  205.             { Since our ID has changed, we need to change our window title }
  206.             GetNameAndTitle (windowTitle, windowName, Handle(hXXXX));
  207.             GetWindowTitle (windowTitle, windowName, TRUE, father);
  208.             name := windowName;                                { Save the new name in my data structure. }
  209.             SetWTitle(wind, windowtitle);            { Set the new window title. }
  210.     
  211.             { Now, let our father object know that our ID has been changed }
  212.             father^^.rebuild := TRUE;                    { Rebuild the picker list. }
  213.             CallInfoUpdate(oldID, newID, LONGINT(father), father^^.wind^.windowKind);
  214.             END; { WITH myXXXX^^ }
  215.         HUnlock(Handle(myXXXX));
  216.         END; { DoInfoUpdate }
  217.  
  218.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  219.         
  220.     FUNCTION IsThisYours (thing: Handle; myXXXX:rXXXXHandle): BOOLEAN;
  221.     
  222.         BEGIN
  223.         IsThisYours := (Handle(myXXXX^^.hXXXX) = thing);
  224.         END;
  225.  
  226.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  227.  
  228.     PROCEDURE DoMenu(Menu, Item:INTEGER; myXXXX:rXXXXHandle);
  229.  
  230.         { Close down the window and get rid of any memory that has been allocated. }
  231.         { Returns TRUE if the operation was successful. If notRevert is false the resource isn't
  232.             released and the data handle isn't disposed (though all the handles it contains
  233.             are disposed). }
  234.         FUNCTION DoClose (notRevert: BOOLEAN): BOOLEAN;
  235.  
  236.             BEGIN
  237.             PassMenu(fileMenu, closeItem, ParentHandle(myXXXX));
  238.             IF WasAborted THEN
  239.                 DoClose := FALSE
  240.             ELSE
  241.                 BEGIN
  242.                 WITH myXXXX^^ DO
  243.                     BEGIN
  244.                     CloseWindow(wind);
  245.                     WindReturn(wind);                        { Mark the window record as being available }
  246.                     SetTheCursor (arrowCursor); { Make sure the cursor is the arrow cursor }
  247.                     
  248.                     { Delete any menus that we added and the redraw menu bar     }
  249.                     { Be sure to dispose of any handles you are done with    }
  250.                     
  251.                     { Release the resource if we were launched from a picker }
  252.                     IF notRevert & resWasntLoaded & (father^^.windowType <> editorWindow) THEN
  253.                         ReleaseResource (Handle(hXXXX));  { Let it be free (if it is not changed)! }
  254.                     END; { WITH myXXXX^^ }
  255.                 IF notRevert THEN
  256.                     DisposHandle(Handle(myXXXX));
  257.                 DoClose := TRUE;
  258.                 END;
  259.             END; { DoClose }
  260.  
  261.         BEGIN {DoMenu}
  262.         BubbleUp(Handle(myXXXX));
  263.         HLock(Handle(myXXXX));
  264.         WITH myXXXX^^ DO
  265.             BEGIN
  266.             SetPort(wind); { Set the port to our window }
  267.             
  268.             { Again, we handle the menu stuff just as we would in a 'real' application
  269.                 except that we only have to handle those items that apply to our editor. }
  270.             CASE Menu OF
  271.                 fileMenu:
  272.                     CASE Item OF
  273.                         CloseItem:
  274.                             BEGIN
  275.                             IF DoClose (TRUE) THEN             {    Close our window }
  276.                                 EXIT(DoMenu);                         {    Return immediately since our resource is gone!    }
  277.                             END; { CloseItem }
  278.                             
  279.                         saveItem:                { Pass the save on to other windows. }
  280.                             PassMenu(fileMenu, saveItem, ParentHandle(myXXXX));
  281.                             
  282.                         printItem:
  283.                             PrintWindow (NIL);
  284.                         END; { Case }
  285.                         
  286.                 rsrcMenu:
  287.                     CASE item OF
  288.                         rsrcRevertItem:
  289.                             BEGIN
  290.                             IF NeedToRevert (wind, Handle(hXXXX)) THEN
  291.                                 BEGIN
  292.                                 { The area under the window will need to be updated }
  293.                                 InvalRect(wind^.portrect);
  294.                                 
  295.                                 { Read in the old copy from disk (see documentation for revertResource).  Clear it out 
  296.                                     unless this  was a newly created resource, in which case don't. }
  297.                                 IF NOT RevertThisResource(ParentHandle(myXXXX), Handle(hXXXX)) THEN
  298.                                     BEGIN        { The resource was newly added so we need to remove it. }                                    
  299.                                     { Make sure that the picker list is rebuilt to remove this item. }
  300.                                     myXXXX^^.father^^.rebuild := TRUE;
  301.                                     
  302.                                     IF DoClose (FALSE) THEN                                            { Close the window. }
  303.                                         BEGIN
  304.                                         RERemoveAnyResource (theResFile, Handle (hXXXX));    { Dispose the resource itself. }
  305.                                         DisposHandle (Handle(myXXXX));
  306.                                         EXIT(DoMenu);
  307.                                         END;
  308.                                     END; {IF NOT RevertResourceノ}
  309.                                 END;
  310.                             END; { RevertItem }
  311.                             
  312.                         rsrcGetInfoItem:
  313.                             BEGIN
  314.                             { Put up the GetInfo window. }
  315.                             ShowInfo(Handle(hXXXX), ParentHandle(myXXXX));
  316.                             END; { GetInfoItem }
  317.                     END; {rsrcmenu: CASE Item OF}
  318.                 EditMenu:
  319.                     CASE Item OF
  320.                         { Implement the edit menu here. }
  321.                         CutItem: ;
  322.                         CopyItem: ;
  323.                         PasteItem: ;
  324.                         ClearItem: ;
  325.                     END; { EditMenu }
  326.                 END; { CASE Menu OF }
  327.             END; { WITH myXXXX^^}
  328.         HUnlock(Handle(myXXXX));
  329.         END; {DoMenu}
  330. END.
  331.